#pragma once

#include <CEGUI/CEGUI.h>
#include <CEGUI/RendererModules/OpenGL/GL3Renderer.h>
#include <osg/BlendFunc>
#include <osg/Drawable>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>

class CEGUIDrawable : public osg::Drawable
{
public:
	CEGUIDrawable();
	CEGUIDrawable(const CEGUIDrawable& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
	META_Object(osg, CEGUIDrawable);

	virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
	void initializeControls();
	bool handleClose(const CEGUI::EventArgs& e);
	bool handleOpen(const CEGUI::EventArgs& e);
	
protected:
	virtual ~CEGUIDrawable() {};

	mutable double _lastSimulationTime;
	mutable unsigned int _activeContextID;
	mutable bool _initialized;
	mutable CEGUI::FrameWindow* _helloWindow;

	
};


class CEGUIEventHandler :public osgGA::GUIEventHandler {
public:
	CEGUIEventHandler(osg::Camera* camera) :_camera(camera) {}
	virtual bool handle(const osgGA::GUIEventAdapter& ea,
		osgGA::GUIActionAdapter& aa);

protected:
	CEGUI::MouseButton convertMouseButton(int button);
	osg::observer_ptr<osg::Camera> _camera;

};
